
cc.Class({
    extends: cc.Component,

    properties: {
        avatar: cc.Sprite,
        nickName: cc.Label,
        data: cc.Label,

        defaultAvatar: cc.SpriteFrame,
        //地域
        location: cc.Node,
        city: cc.Label,
    },

    /**
     * data属性为： 
     * 
     * avatarUrl
     * city
     * nickName
     * data
     */
    init(data){
        if(data){
            this.loadAvatar(data.avatarUrl, this.avatar);//根据头像url加载玩家头像
            this.nickName.string = data.nickName;//昵称省略...处理
            this.data.string = "第" + data.data + "关";//关卡数
            if(data.city){
                this.location.active = true;
                this.city.string = data.city;
            }else{
                this.location.active = false;
            }
        }else{
            this.avatar.spriteFrame = this.defaultAvatar;
            this.nickName.string = "";
            this.data.string = "";
            this.location.active = false;
        }
    },

    loadAvatar(url, sprite){
        try{
            cc.loader.load({url: url, type: 'png'}, function (err, texture) {
                if(err){
                    console.error(err.message || err);
                }
                sprite.spriteFrame = new cc.SpriteFrame(texture);
            });
        }catch(e){
            console.error(e);
            sprite.node.active = false;
        }
    },

    
});
